using ns0;
using ns4;
using System;
namespace ns10
{
	internal sealed class Class22
	{
		private BitMatrix bitMatrix_0;
		private Version version_0;
		private Class11 class11_0;
		internal Class22(BitMatrix bitMatrix_1)
		{
			int dimension = bitMatrix_1.Dimension;
			if (dimension < 21 || (dimension & 3) != 1)
			{
				throw ReaderException.Instance;
			}
			this.bitMatrix_0 = bitMatrix_1;
		}
		internal Class11 method_0()
		{
			Class11 result;
			if (this.class11_0 != null)
			{
				result = this.class11_0;
			}
			else
			{
				int num = 0;
				for (int i = 0; i < 6; i++)
				{
					num = this.method_2(i, 8, num);
				}
				num = this.method_2(7, 8, num);
				num = this.method_2(8, 8, num);
				num = this.method_2(8, 7, num);
				for (int j = 5; j >= 0; j--)
				{
					num = this.method_2(8, j, num);
				}
				this.class11_0 = Class11.smethod_1(num);
				if (this.class11_0 != null)
				{
					result = this.class11_0;
				}
				else
				{
					int dimension = this.bitMatrix_0.Dimension;
					num = 0;
					int num2 = dimension - 8;
					for (int i = dimension - 1; i >= num2; i--)
					{
						num = this.method_2(i, 8, num);
					}
					for (int j = dimension - 7; j < dimension; j++)
					{
						num = this.method_2(8, j, num);
					}
					this.class11_0 = Class11.smethod_1(num);
					if (this.class11_0 == null)
					{
						throw ReaderException.Instance;
					}
					result = this.class11_0;
				}
			}
			return result;
		}
		internal Version method_1()
		{
			Version versionForNumber;
			if (this.version_0 != null)
			{
				versionForNumber = this.version_0;
			}
			else
			{
				int dimension = this.bitMatrix_0.Dimension;
				int num = dimension - 17 >> 2;
				if (num <= 6)
				{
					versionForNumber = Version.getVersionForNumber(num);
				}
				else
				{
					int num2 = 0;
					int num3 = dimension - 11;
					for (int i = 5; i >= 0; i--)
					{
						for (int j = dimension - 9; j >= num3; j--)
						{
							num2 = this.method_2(j, i, num2);
						}
					}
					this.version_0 = Version.smethod_0(num2);
					if (this.version_0 != null && this.version_0.DimensionForVersion == dimension)
					{
						versionForNumber = this.version_0;
					}
					else
					{
						num2 = 0;
						for (int j = 5; j >= 0; j--)
						{
							for (int i = dimension - 9; i >= num3; i--)
							{
								num2 = this.method_2(j, i, num2);
							}
						}
						this.version_0 = Version.smethod_0(num2);
						if (this.version_0 == null || this.version_0.DimensionForVersion != dimension)
						{
							throw ReaderException.Instance;
						}
						versionForNumber = this.version_0;
					}
				}
			}
			return versionForNumber;
		}
		private int method_2(int int_0, int int_1, int int_2)
		{
			return this.bitMatrix_0.get_Renamed(int_0, int_1) ? (int_2 << 1 | 1) : (int_2 << 1);
		}
		internal sbyte[] method_3()
		{
			Class11 @class = this.method_0();
			Version version = this.method_1();
			Class13 class2 = Class13.smethod_0((int)@class.method_1());
			int dimension = this.bitMatrix_0.Dimension;
			class2.method_0(this.bitMatrix_0, dimension);
			BitMatrix bitMatrix = version.method_0();
			bool flag = true;
			sbyte[] array = new sbyte[version.TotalCodewords];
			int num = 0;
			int num2 = 0;
			int num3 = 0;
			for (int i = dimension - 1; i > 0; i -= 2)
			{
				if (i == 6)
				{
					i--;
				}
				for (int j = 0; j < dimension; j++)
				{
					int int_ = flag ? (dimension - 1 - j) : j;
					for (int k = 0; k < 2; k++)
					{
						if (!bitMatrix.get_Renamed(i - k, int_))
						{
							num3++;
							num2 <<= 1;
							if (this.bitMatrix_0.get_Renamed(i - k, int_))
							{
								num2 |= 1;
							}
							if (num3 == 8)
							{
								array[num++] = (sbyte)num2;
								num3 = 0;
								num2 = 0;
							}
						}
					}
				}
				flag = !flag;
			}
			if (num != version.TotalCodewords)
			{
				throw ReaderException.Instance;
			}
			return array;
		}
	}
}
